<?php $this->load->view('layout/header'); ?>
<div class="supplier-content-page">
    <div class="product-test-h5">
        <ul class="breadcrumb">
            <li><a href="javascript:;">商品管理</a></li>
            <li><a href="<?php echo site_url('tourismorder/grid')?>">订单管理</a></li>
            <li class="active"><a href="javascript:;">订单详情</a></li>
        </ul>
        <div class="buy-order clearfix">
            <ul class="buy-ul">
                <li class="status">
                    <div class="status-label <?php if ($orderInfo->order_status == 2) : ?>fust<?php endif; ?>">生成订单</div>
                    <div class="icon-image <?php if ($orderInfo->order_status < 2) : ?>adds<?php endif ?>">1</div>
                    <div class="status-xian <?php if ($orderInfo->order_status < 3) : ?>adds<?php endif ?>"></div>
                    <div class="status-time"><?php if ($orderInfo->order_status >= 1) : ?><?php echo $orderInfo->created_at ?><?php endif ?></div>
                </li>
                <li class="status">
                    <div class="status-label <?php if ($orderInfo->order_status == 3) : ?>fust<?php endif ?>">支付订单</div>
                    <div class="icon-image <?php if ($orderInfo->order_status < 3) : ?>adds<?php endif ?>">2</div>
                    <div class="status-xian <?php if ($orderInfo->order_status < 4) : ?>adds<?php endif ?>"></div>
                    <div class="status-time "><?php if ($orderInfo->order_status > 2) : ?><?php echo $orderInfo->pay_time ?><?php endif ?></div>
                </li>
                <li class="status">
                    <div class="status-label <?php if ($orderInfo->order_status == 4) : ?>fust<?php endif ?>">卖家发货</div>
                    <div class="icon-image <?php if ($orderInfo->order_status < 4) : ?>adds<?php endif ?>">3</div>
                    <div class="status-xian <?php if ($orderInfo->order_status < 5) : ?>adds<?php endif ?>"></div>
                    <div class="status-time"><?php if ($orderInfo->order_status > 3) : ?><?php echo $orderInfo->send_time ?><?php endif ?></div>
                </li>
                <li class="status">
                    <div class="status-label <?php if ($orderInfo->order_status == 5) : ?>fust<?php endif ?>">确认收货</div>
                    <div class="icon-image <?php if ($orderInfo->order_status < 5) : ?>adds<?php endif ?>">4</div>
                    <div class="status-xian  <?php if ($orderInfo->order_status < 6) : ?>adds<?php endif ?>"></div>
                    <div class="status-time"><?php if ($orderInfo->order_status > 4) : ?><?php echo $orderInfo->receive_time ?><?php endif ?></div>
                </li>
                <li class="status">
                    <div class="status-label <?php if ($orderInfo->order_status == 6) : ?>fust<?php endif ?>"> 评　价</div>
                    <div class="icon-image <?php if ($orderInfo->order_status < 6) : ?>adds<?php endif ?>">6</div>
                    <div class="status-time"><?php if ($orderInfo->order_status > 5) : ?><?php echo $orderInfo->reviews_time ?><?php endif ?></div>
                </li>
            </ul>
        </div>
        <?php echo execute_alert_message() ?>
        <div class="order-infom clearfix">
            <div class="infom-left clearfix">
                <div class="fonter">订单信息</div>
                <div class="infom-body">
                    <div class="body-first clearfix">
                        <p class="show">收货地址：</p>
                        <p class="dizet">
                            <?php $address = json_decode($orderInfo->detail); ?>
                            <span><?php echo $address->receiver_name ?>，<?php echo $address->tel ?>, <?php echo $address->code ?></span>
                            <span><?php echo $address->detailed ?></span>
                        </p>
                    </div>
                    <div class="body-last clearfix">
                        <p class="show">购买时间：</p>
                        <p><?php echo $orderInfo->created_at ?></p>
                    </div>
                    <div class="body-secend border-topb clearfix">
                        <p class="show">订单编号：</p>
                        <p><?php echo $orderInfo->order_sn ?></p>
                    </div>
                    <?php if ($orderInfo->order_status == 2) :?>
                    <div class="body-secend clearfix">
                        <p class="show">运费：</p>
                        <input class="transport-value" type="text" name="transport_cost"  value="<?php echo $orderInfo->transport_cost;?>" onkeyup="this.value=this.value.replace(/\D/g,'')"/><button type="button"  class="modify-transport" order_id="<?php echo $orderInfo->order_id;?>" value="确定">确定</button>
                    </div>
                    <?php endif;?>
                    <div class="body-secend clearfix">
                        <p class="show">发票抬头：</p>
                        <p class="dizet">
                            <span><?php echo $orderInfo->vanguard ?></span>
                        </p>
                    </div>
                    <div class="body-secend clearfix">
                        <p class="show">发票内容：</p>
                        <p class="dizet">
                            <span>明细</span>
                        </p>
                    </div>
                    <div class="body-last clearfix">
                        <p class="show">客户留言：</p>
                        <p class="dizet">
                            <span><?php echo $orderInfo->message ?></span>
                        </p>
                    </div>
                </div>
            </div>
            <div class="infom-right">
                <div class="first-sub">
                    <div class="first-group"><span>！</span>订单状态：
                        <?php if ($orderInfo->order_status == 1): ?>订单已关闭<?php endif; ?>
                        <?php if ($orderInfo->order_status == 2): ?>待付款<?php endif; ?>
                        <?php if ($orderInfo->order_status == 3): ?>待发货<?php endif; ?>
                        <?php if ($orderInfo->order_status == 4): ?>待收货<?php endif; ?>
                        <?php if ($orderInfo->order_status == 5): ?>待评价<?php endif; ?>
                        <?php if ($orderInfo->order_status == 6): ?>已评价<?php endif; ?>
                    </div>
                    <?php if ($orderInfo->order_status == 3): ?>
                        <a href="javascript:;" class="logistics" data-toggle="modal" data-target="#logistics">填写运单号</a>
                    <?php endif; ?>
                    
                    <?php 
                        $time = strtotime($orderInfo->send_time) - time() + 3600 * 24 * 7;
                        if ($orderInfo->receive_time != '0000-00-00 00:00:00') {
                            $time = strtotime($orderInfo->receive_time) - time() + 3600 * 24 * 7;
                        }
                    ?>
                    <?php if ($orderInfo->order_status == 4): ?>
                        <?php if ($time > 0): ?>
                            <p>还有<span>
                            <?php
                            $days = intval($time / 86400);
                            $remain = $time % 86400;
                            $hours = intval($remain / 3600);
                            $remain = $remain % 3600;
                            $mins = intval($remain / 60);
                            $secs = $remain % 60;
                            ?>
                            <?php echo $days ?>天<?php echo $hours ?>小时<?php echo $mins ?>分</span>来确认收货，超时订单自动确认收货</p>
                        <?php endif; ?>
                    <?php endif; ?>
                    <?php if ($orderInfo->order_status == 5): ?>
                        <span class="logistics">已收货,待评价</span>
                        <?php if ($time > 0): ?>
                            <p>还有<span>
                            <?php
                            $days = intval($time / 86400);
                            $remain = $time % 86400;
                            $hours = intval($remain / 3600);
                            $remain = $remain % 3600;
                            $mins = intval($remain / 60);
                            $secs = $remain % 60;
                            ?>
                            <?php echo $days ?>天<?php echo $hours ?>小时<?php echo $mins ?>分</span>来评价，超时订单将自动好评</p>
                        <?php endif; ?>
                    <?php endif; ?>
                    <?php if ($orderInfo->order_status == 4): ?>
                        <br/>
                        <a href="javascript:;" class="logistics" data-toggle="modal" data-target="#logistics">修改运单号</a>
                    <?php endif; ?>
                </div>
            </div>
        </div>
        <div class="table-infom">            
            <table class="table">
                <thead>
                    <tr>
                        <th>商品名称</th>
                        <th>销售价/供应价</th>
                        <th>购买数量</th>
                        <th>退货数量</th>
                        <th>换货数量</th>
                        <th>实际应付（元）</th>
                        <th>购买形式</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <?php if ($orderInfo->order_status > 3 && $logistics->num_rows() > 0): ?>
                        <?php $logistics = $logistics->row(); ?>
                        <td colspan="7" class="colspans">
                            <p>物流公司：<?php echo $logistics->name;?></p>
                            <p>运单号：<?php echo $logistics->number;?></p>
                            <div class="col-span">物流跟踪<i class="glyphicon glyphicon-menu-down"></i>
                                <div class="col-clike">
                                    <i class="sjicon"></i>
                                    <p class="col-lebel">
                                        <span>物流公司：<?php echo $logistics->name;?></span>
                                        <span>运单号：<?php echo $logistics->number;?></span>
                                    </p>
                                    <div class="col-scroll">
                                        <table width="520px" cellspacing="0" cellpadding="0" border="0" class="express-table">
                                            <tbody>
                                            <tr>
                                                <th width="163" >时间</th>
                                                <th width="354" >地点和跟踪进度</th>
                                            </tr>
                                            <?php if(!empty($logistics->context)): ?>
                                            <?php $data = json_decode($logistics->context); ?>
                                            <?php foreach($data as $value): ?>
                                                <tr>
                                                    <td width="163" ><?php echo $value->time; ?></td>
                                                    <td width="354" ><?php echo $value->context; ?></td>
                                                </tr>
                                            <?php endforeach ?>
                                            <?php endif ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </td>
                        <?php endif ?>
                    </tr>
                </tbody>
                <tbody>
                <?php foreach ($orderProductInfo->result() as $item) : ?>
                    <tr>
                        <td class="baobei">
                            <div class="media">
                                <div class="media-left">
                                    <a target="_blank" href="<?php echo $this->config->wap_base_url.'tourism/goods/info/'.$item->goods_attr_id.'.html' ?>">
                                        <img class="media-object lazy" src="skins/images/load.jpg" data-original="<?php echo $this->config->show_image_url($item->goods_image) ?>" style="width: 80px; height: 80px;">
                                    </a>
                                </div>
                                <div class="media-body">
                                    <h4 class="media-heading"><?php echo $item->goods_name ?></h4>
                                    <span><?php echo $item->attribute_value ?></span>
                                </div>
                            </div>
                        </td>
                        <td><?php echo $item->shop_price; ?> / <?php echo $item->supply_price; ?></td>
                        <td><?php echo $item->number?></td>
                        <td><?php echo bcsub($item->number, $item->refund_num, 0);?></td>
                        <td><?php echo $item->barter_num?></td>
                        <td class="pirce"><strong class="text-primary"><?php echo $item->pay_amount;?></strong></td>
                        <td><?php echo $item->calculate_method == 1 ? '分润' : '议价'; ?></td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
<div id="logistics" class="modal fade logistics-pop">
    <div class="modal-dialog">
        <form class="form-horizontal logistics-validate-form" action="<?php echo site_url('tourismorder/logisticsPost') ?>" method="post">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title"><span>！</span>提交运单号</h4>
                </div>
                <div class="modal-body">
                    <div class="alert alert-warning" role="alert">
                        <strong>注意：</strong>确认发货后，若客户申请退款，将不再退还运费，请确认无误后再发货。
                        <p>如果没有您需要选择的物流公司，请拨打400-0571-648，反馈与我们添加。谢谢！</p>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">选择物流公司</label>
                        <div class="col-xs-5">
                            <input type="hidden" value="<?php echo $orderInfo->order_id ?>" name="logistics_order_id">
                            <select name="logistics_company" class="form-control required">
                                <option value="">请选择物流公司</option>
                                <?php foreach ($logisticsAll->result() as $val) : ?>
                                    <option value="<?php echo $val->company ?>"><?php echo $val->name ?></option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">填写运单编号</label>
                        <div class="col-xs-5">
                            <input type="text" class="form-control required number" name="logistics">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-warning">保存</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
   $('.logistics-validate-form').validate();
   $('.body-secend').on('click','.modify-transport',function(){
      if (confirm('确定修改运费吗?')) {
       	 var order_id = $(this).attr('order_id');
         var transportPrice = parseFloat($('input[name=transport_cost]').val());
         $.ajax({
             type: 'post',
             async: true,
             dataType: 'json',
             url: hostUrl() + '/tourismorder/modifyTransport',
             data: {transport_cost:transportPrice,order_id:order_id},
             success: function (data) {
                 if (data.status) {
                     alert('修改成功')
                 } else {
                     alert(data.msg);
                 }
             }
         });
     }
   });
</script>
<?php $this->load->view('layout/footer'); ?>